package com.system.borrow.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.system.borrow.R;
import com.system.borrow.bean.UserData;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：Administrator
 * 日期：2016/12/13/013 17:43
 * 说明：
 */
public class UserAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater inflater;
    List<UserData> list = new ArrayList<>();


    public List<UserData> getList() {
        return list;
    }

    public void setList(List<UserData> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public UserAdapter(Context context) {
        super();
        this.mContext = context;
        this.inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.layout_popupwindow_item, null);
            holder.tv_text = (TextView) convertView.findViewById(R.id.tv_text);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        UserData data = list.get(position);
        holder.tv_text.setText(data.getText());
        return convertView;
    }

    class ViewHolder {
        TextView tv_text;
    }
}
